b5eac9
@@ -197,7 +197,7 @@
public static Statistics collectStatistics(HiveConf conf, PrunedPartitionList pa
       if (fetchColStats) {
         colStats = getTableColumnStats(table, schema, neededColumns);
         long betterDS = getDataSizeFromColumnStats(nr, colStats);
-        ds = betterDS < 1 ? ds : betterDS;
+        ds = (betterDS < 1 || colStats.isEmpty()) ? ds : betterDS;
       }
        stats.setDataSize(ds);
       // infer if any column can be primary key based on column statistics
@@ -298,7 +298,7 @@
public static Statistics collectStatistics(HiveConf conf, PrunedPartitionList pa
           addParitionColumnStats(conf, neededColumns, referencedColumns, schema, table, partList,
               columnStats);
           long betterDS = getDataSizeFromColumnStats(nr, columnStats);
-          stats.setDataSize(betterDS < 1 ? ds : betterDS);
+          stats.setDataSize((betterDS < 1 || columnStats.isEmpty()) ? ds : betterDS);
           // infer if any column can be primary key based on column statistics
           inferAndSetPrimaryKey(stats.getNumRows(), columnStats);
 
@@ -1434,10 +1434,17 @@
public static long getBasicStatForTable(Table table, String statType) {
   public static long getDataSizeFromColumnStats(long numRows, List<ColStatistics> colStats) {
     long result = 0;
 
-    if (numRows <= 0 || colStats == null || colStats.isEmpty()) {
+    if (numRows <= 0 || colStats == null) {
       return result;
     }
 
+    if (colStats.isEmpty()) {
+      // this may happen if we are not projecting any column from current operator
+      // think count(*) where we are projecting rows without any columns
+      // in such a case we estimate empty row to be of size of empty java object.
+      return numRows * JavaDataModel.JAVA64_REF;
+    }
+
     for (ColStatistics cs : colStats) {
       if (cs != null) {
         String colTypeLowerCase = cs.getColumnType().toLowerCase();
